package bg.code.commons.plugin.ui.table;

import bg.code.commons.builder.dto.ResultDTO;
import bg.code.commons.builder.utils.Strings;
import bg.code.commons.builder.vo.AuthorDescriptor;
import com.intellij.ui.components.JBTextArea;
import com.intellij.ui.components.panels.VerticalBox;

import javax.swing.*;

import static bg.code.commons.plugin.Cons.*;

/**
 * @author 郑兴泉 956607644@qq.com
 * @data 2020/8/11
 * 描述：
 */
public final class AuthorJBPanel implements ICustomJBPanel<JBTextArea> {


    private final JBTextArea authorTextArea;
    private final JBTextArea funNameTextArea;
    private final JBTextArea userMailTextArea;

    public AuthorJBPanel() {
        authorTextArea = new JBTextArea();
        funNameTextArea = new JBTextArea(3, 4);
        userMailTextArea = new JBTextArea();
    }

    @Override
    public JComponent getComponent() {
        VerticalBox root = new VerticalBox();
        root.setBorder(BorderFactory.createTitledBorder(CLASS_ANNOTATION_INFO));
        root.add(new JLabel(AUTHOR_TEXT));
        root.add(authorTextArea);
        root.add(new JLabel(FUN_NAME_TEXT));
        root.add(funNameTextArea);
        root.add(new JLabel(USER_MAIL_TEXT));
        root.add(userMailTextArea);
        return root;
    }

    @Override
    public JBTextArea getObj() {
        return null;
    }

    @Override
    public AuthorDescriptor getData() {
        return new AuthorDescriptor(authorTextArea.getText(), userMailTextArea.getText(), funNameTextArea.getText());
    }

    public JBTextArea getAuthorTextArea() {
        return authorTextArea;
    }

    public JBTextArea getFunNameTextArea() {
        return funNameTextArea;
    }

    public JBTextArea getUserMailTextArea() {
        return userMailTextArea;
    }

    @Override
    public ResultDTO errorMsg() {
        if (Strings.isBlank(authorTextArea.getText())) {
            return new ResultDTO(false, AUTHOR_TEXT_ERROR_MSG);
        }
//        if(Strings.isBlank(funNameTextArea.getText())){
//            return new ResultDTO(false,FUN_NAME_TEXT_ERROR_MSG);
//        }
        if (Strings.isBlank(userMailTextArea.getText())) {
            return new ResultDTO(false, USER_MAIL_TEXT_ERROR_MSG);
        }
        return new ResultDTO(true, "");
    }
}
